New function to create a blank pixbuf.
authorHavoc Pennington <hp@pobox.com>
Wed, 27 Oct 1999 17:28:44 +0000 (17:28 +0000)
committerHavoc Pennington <hp@src.gnome.org>
Wed, 27 Oct 1999 17:28:44 +0000 (17:28 +0000)
1999-10-27  Havoc Pennington  <hp@pobox.com>

* src/gdk-pixbuf.c (gdk_pixbuf_new): New function to create a
blank pixbuf.

* src/gdk-pixbuf-loader.c (gdk_pixbuf_loader_write): Check all
three progressive load funcs are non-NULL, rather than checking
begin_load three times. Also, check whether begin_load returns
NULL on failure.

gdk-pixbuf/gdk-pixbuf-loader.c
gdk-pixbuf/gdk-pixbuf.c
gdk-pixbuf/gdk-pixbuf.h
gtk/gdk-pixbuf-loader.c

index ef6c076094761f2f1496b4cb6e6b442180f69b29..a86736e0e919322f75fb6dd35a476005420df5fe 100644 (file)
@@ -240,14 +240,19 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
                        if (priv->image_module == NULL) {
                                return FALSE;
                        } else if ((priv->image_module->begin_load == NULL) ||
-                                  (priv->image_module->begin_load == NULL) ||
-                                  (priv->image_module->begin_load == NULL) ||
-                                  (priv->image_module->begin_load == NULL)) {
+                                  (priv->image_module->stop_load == NULL) ||
+                                  (priv->image_module->load_increment == NULL)) {
                                g_warning ("module %s does not support incremental loading.\n", priv->image_module->module_name);
                                return FALSE;
                        } else {
                                g_print ("module loaded: name is %s\n", priv->image_module->module_name);
                                priv->context = (priv->image_module->begin_load) (gdk_pixbuf_loader_prepare, loader);
+
+                                if (priv->context == NULL) {
+                                        g_warning("Failed to begin progressive load");
+                                        return FALSE;
+                                }
+                                
                                retval = (priv->image_module->load_increment) (priv->context, priv->buf, 128);
 
                                /* if we had more then 128 bytes total, we want to send the rest of the buffer */
index a35ac01c463747a583ad8cd50edf12d350418775..924f987bcc41fdef608c3599233d8be241f6c3ef 100644 (file)
@@ -99,3 +99,64 @@ gdk_pixbuf_new_from_art_pixbuf (ArtPixBuf *art_pixbuf)
 
        return pixbuf;
 }
+
+/**
+ * gdk_pixbuf_new:
+ * @art_pixbuf: A libart pixbuf.
+ *
+ * Creates a &GdkPixbuf; magically sets the ArtPixFormat, rowstride, and creates
+ * the buffer. Use gdk_pixbuf_new_from_data() to do things manually.
+ *
+ * Return value: A newly-created &GdkPixbuf structure with a reference count of
+ * 1. Somewhat oddly, returns NULL if it can't allocate the buffer; this unusual
+ * behavior is needed because images can be very large.
+ **/
+GdkPixbuf *
+gdk_pixbuf_new (gboolean has_alpha, int width, int height)
+{
+        GdkPixbuf *pixbuf;
+
+       g_return_val_if_fail (width > 0, NULL);
+        g_return_val_if_fail (height > 0, NULL);
+
+       pixbuf = g_new (GdkPixbuf, 1);
+       pixbuf->ref_count = 1;
+        
+        if (has_alpha) {
+                art_u8* pixels;
+                int rowstride;
+
+                /* FIXME, pick an optimal stride */                
+                rowstride = 4*width;
+
+                pixels = art_alloc(rowstride*height);
+
+                if (pixels == NULL) {
+                        g_free(pixbuf);
+                        return NULL;
+                }
+                
+                pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, width, height, rowstride);
+        } else {
+                art_u8* pixels;
+                int rowstride;
+
+                /* FIXME, pick an optimal stride */
+                rowstride = 3*width;
+
+                pixels = art_alloc(rowstride*height);
+
+                if (pixels == NULL) {
+                        g_free(pixbuf);
+                        return NULL;
+                }
+
+                pixbuf->art_pixbuf = art_pixbuf_new_rgb(pixels, width, height, rowstride);
+        }
+                
+       return pixbuf;
+
+
+}
+
+
index ec42cf3eae1f11de7286484a571028ab99b5e3ea..47fce2177726a66242bee29d105f60ddc3db4ebf 100644 (file)
@@ -59,6 +59,9 @@ void gdk_pixbuf_unref (GdkPixbuf *pixbuf);
 
 GdkPixbuf *gdk_pixbuf_new_from_art_pixbuf (ArtPixBuf *art_pixbuf);
 
+/* Create a "blank" pixbuf with an optimal rowstride and a new buffer */
+GdkPixbuf *gdk_pixbuf_new (gboolean has_alpha, int width, int height);
+
 /* Simple loading */
 
 GdkPixbuf *gdk_pixbuf_new_from_file (const char *filename);
index ef6c076094761f2f1496b4cb6e6b442180f69b29..a86736e0e919322f75fb6dd35a476005420df5fe 100644 (file)
@@ -240,14 +240,19 @@ gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
                        if (priv->image_module == NULL) {
                                return FALSE;
                        } else if ((priv->image_module->begin_load == NULL) ||
-                                  (priv->image_module->begin_load == NULL) ||
-                                  (priv->image_module->begin_load == NULL) ||
-                                  (priv->image_module->begin_load == NULL)) {
+                                  (priv->image_module->stop_load == NULL) ||
+                                  (priv->image_module->load_increment == NULL)) {
                                g_warning ("module %s does not support incremental loading.\n", priv->image_module->module_name);
                                return FALSE;
                        } else {
                                g_print ("module loaded: name is %s\n", priv->image_module->module_name);
                                priv->context = (priv->image_module->begin_load) (gdk_pixbuf_loader_prepare, loader);
+
+                                if (priv->context == NULL) {
+                                        g_warning("Failed to begin progressive load");
+                                        return FALSE;
+                                }
+                                
                                retval = (priv->image_module->load_increment) (priv->context, priv->buf, 128);
 
                                /* if we had more then 128 bytes total, we want to send the rest of the buffer */